layui.use(['layer', 'form', 'jquery'], function () {

    document.querySelector('#formRegister').addEventListener('submit', function (e) {
        e.preventDefault();
    }, false);

    var layer = layui.layer,
        form = layui.form(),
        $ = layui.jquery;

    form.verify({
        passwordCheck: function (value) {
            var pwd = document.getElementById("inputPassword").value;
            if (pwd !== value) {
                return '两次输入的密码不一致！';
            }
        }
    });

    form.on('submit(buttonSubmit)', function (data) {
        $.ajax({
            method:'POST',
            url: 'register/doRegister',
            data: data.field,
            success:function(json){
                if(json.status) {
                    layer.open({
                        title: '提示',
                        content: '注册成功',
                        btn:'前往登陆',
                        yes:function(index,layero){
                            location.href='/login'
                        }
                    });
                }else{
                    layer.msg('注册失败!');
                }
            },
            error:function(){
                layer.msg('网络错误!');
            }
        });
        return false;
    });
});